package com.ruoyi.wx.mapper;

import java.util.Date;
import java.util.List;

import com.ruoyi.info.domain.VinfoCar;
import com.ruoyi.wx.domain.VehiclesLog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 车辆日志Mapper接口
 *
 * @author oy
 * @date 2022-12-13
 */
public interface VehiclesLogMapper
{
    /**
     * 查询车辆日志
     *
     * @param vehicleLogId 车辆日志主键
     * @return 车辆日志
     */
    public VehiclesLog selectVehiclesLogByVehicleLogId(Long vehicleLogId);

    /**
     * 查询车辆日志列表
     *
     * @param vehiclesLog 车辆日志
     * @return 车辆日志集合
     */
    public List<VehiclesLog> selectVehiclesLogList(VehiclesLog vehiclesLog);

    /**
     * 新增车辆日志
     *
     * @param vehiclesLog 车辆日志
     * @return 结果
     */
    public int insertVehiclesLog(VehiclesLog vehiclesLog);

    /**
     * 修改车辆日志
     *
     * @param vehiclesLog 车辆日志
     * @return 结果
     */
    public int updateVehiclesLog(VehiclesLog vehiclesLog);

    /**
     * 删除车辆日志
     *
     * @param vehicleLogId 车辆日志主键
     * @return 结果
     */
    public int deleteVehiclesLogByVehicleLogId(Long vehicleLogId);

    /**
     * 批量删除车辆日志
     *
     * @param vehicleLogIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteVehiclesLogByVehicleLogIds(Long[] vehicleLogIds);

//    @Select("select DISTINCT gps_time,event_desc from vehicles_log where device_no = #{deviceNo} and speed = 0 and gps_time > #{beginTime} and gps_time < #{endTime} ORDER BY gps_time desc")
    List<VehiclesLog> selectToCountWeight(@Param("carNo") Long carNo, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    @Select("select sum(ifnull(weight,0)) from vinfo_count_order where car_no = #{carNo} and begin_time > #{beginTime} and end_time < #{endTime}")
    Double selectCountWeight(@Param("carNo") String carNo, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    @Select("select min(gps_time) from vehicles_log")
    Date selectEarliestDate();

    List<VehiclesLog> selectByCarNoAndDateRange(@Param("deviceNo") Long deviceNo,@Param("carNo")String carNo, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    List<VinfoCar> selectCar();

    @Delete("delete from vehicles_log where create_time < #{date}")
    void deleteVehiclesLogByVehicleLogCreateTime(Date date);
}
